#include "Comm.hpp"

#include <unistd.h>
int main()
{
    Fifo ff(Path);
    sleep(1);


    int read_fd = open(Path,O_RDONLY);
    if(read_fd < 0)
    {
        cerr << "open fail:->errno->" << errno<< "->"<<strerror(errno) << endl;
        return 1;
    }

    cout << "open success" << endl;
    char buffer[1024];
    while(1)
    {
        ssize_t n = read(read_fd,buffer,sizeof(buffer)-1);
        if(n < 0)
        {
             cerr << "read fail:->errno->" << errno<< "->"<<strerror(errno) << endl;
             break;
        }
        else if(n == 0)
        {
            //读到了文件尾
            cout << "client quit,server close" << endl;
            break;
        }
        else {
            buffer[n] = 0;
            cout << "client say " << buffer << endl;
        }
    }

    close(read_fd);
    return 0;
}